<?php
namespace app;
use App;
class BaseObject{
	public function __construct($config = [])
    {
        if (!empty($config)) {
            App::configure($this, $config);
        }
        $this->init();
    }
    public function init()
    {

    }
    public function beforeRoute(){
        if(!defined('VF_TOKEN')){
            die();
        }
        return true;
    }
	public function __call($name, $params)
    {
        if (method_exists($this, $name)) {
            return call_user_func_array([$this, $name], $params); // 调用原来的方法
        } else {
            throw new \BadMethodCallException("方法 '$name' 不存在");
        }
    }

    public function __get($name)
    {
        $getter = 'get' . $name;
        if (method_exists($this, $getter)) {
            return $this->$getter();
        } elseif (method_exists($this, 'set' . $name)) {
            throw new \Exception('Getting write-only property: ' . get_class($this) . '::' . $name, 5000);
        }

        throw new \Exception('Getting unknown property: ' . get_class($this) . '::' . $name, 5000);
    }

    public function __set($name, $value)
    {
        $setter = 'set' . $name;
        if (method_exists($this, $setter)) {
            $this->$setter($value);
        } elseif (method_exists($this, 'get' . $name)) {
            throw new \Exception('Setting read-only property: ' . get_class($this) . '::' . $name, 5000);
        } else {
            throw new \Exception('Setting unknown property: ' . get_class($this) . '::' . $name, 5000);
        }
    }
}